//
//  IFlySynthesis.h
//  Learn
//
//  Created by cjg.mini on 2024/4/8.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "IFlyMSC/IFlyMSC.h"
#import "PcmPlayer.h"

typedef NS_OPTIONS(NSInteger, SynthesizeType) {
    NomalType           = 5,    //Normal TTS
    UriType             = 6,    //URI TTS
};

//state of TTS
typedef NS_OPTIONS(NSInteger, Status) {
    NotStart            = 0,
    Playing             = 2,
    Paused              = 4,
};

@class IFlySpeechSynthesizer;

@class IFlySynthesis;


@protocol IFlySynthesisDelegate<NSObject>

/*!
 *  结束回调<br>
 *  当整个合成结束之后会回调此函数
 *  @param error 错误码
 */
- (void) onCompleted:(IFlySpeechError*) error;

/*!
 *  开始合成回调
 */
- (void) onSpeakBegin;

/*!
 *  缓冲进度回调
 *
 *  @param progress 缓冲进度，0-100
 *  @param msg      附件信息，此版本为nil
 */
- (void) onBufferProgress:(int) progress message:(NSString *)msg;

/*!
 *  播放进度回调
 *
 *  @param progress 当前播放进度，0-100
 *  @param beginPos 当前播放文本的起始位置（按照字节计算），对于汉字(2字节)需／2处理
 *  @param endPos 当前播放文本的结束位置（按照字节计算），对于汉字(2字节)需／2处理
 */
- (void) onSpeakProgress:(int) progress beginPos:(int)beginPos endPos:(int)endPos;

/*!
 *  暂停播放回调
 */
- (void) onSpeakPaused;


@end

@interface IFlySynthesis : NSObject

@property (nonatomic, strong) IFlySpeechSynthesizer * iFlySpeechSynthesizer;

@property (nonatomic,assign) id<IFlySynthesisDelegate> delegate;

@property (nonatomic, assign) BOOL isCanceled;
@property (nonatomic, assign) BOOL hasError;
@property (nonatomic, assign) BOOL isViewDidDisappear;


@property (nonatomic, strong) NSString *uriPath;
@property (nonatomic, strong) PcmPlayer *audioPlayer;

@property (nonatomic, assign) Status state;
@property (nonatomic, assign) SynthesizeType synType;

- (void)startNomalSynthesisWith:(NSString *)text;
- (void)startURISynthesisWith:(NSString *)text;
- (void)cancel;
- (void)pause;
- (void)resume;

@end
